package com.lgw.customers.controller;

import com.lgw.commons.dto.CustomersDTO;
import com.lgw.commons.model.domain.ResultInfo;
import com.lgw.commons.utils.ResultInfoUtil;
import com.lgw.customers.service.CustomersService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * 顾客服务控制层
 */
@RestController
@Api(tags = "顾客相关接口")
public class CustomersController {

    @Autowired
    private CustomersService customersService;

    @Autowired
    private HttpServletRequest request;

    /**
     * 注册
     *
     * @param customersDTO
     * @return
     */
    @PostMapping("register")
    public ResultInfo register(@RequestBody CustomersDTO customersDTO) {
        return customersService.register(customersDTO, request.getServletPath());
    }

    /**
     * 校验手机号是否已注册
     *
     * @param phone
     * @return
     */
    @GetMapping("checkPhone")
    public ResultInfo checkPhone(String phone) {
        customersService.checkPhoneIsRegistered(phone);
        return ResultInfoUtil.buildSuccess(request.getServletPath());
    }

    /**
     * 登录
     *
     * @param account
     * @param password
     * @return
     */
    @GetMapping("signin")
    public ResultInfo signIn(String account, String password) {
        return customersService.signIn(account, password, request.getServletPath());
    }

}
